<?php
/*
 * Created on Sep 13, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
include_once("./configure/configure.php");		//--> global var
include_once("Smarty.class.php");				//--> out template
include_once("Common.php");
include_once("UploadFiles.php");				//--> UploadFiles
include_once("customerSession.inc.php");
include_once ("Session.php");					//-- Session
include_once("Orders.php");						//--> Orders

include_once("Strings.php");					//--> String utils
include_once("TimeZone.php");						//--> TimeZone

include_once("orders/Cart.php");					//--> Cart
include_once("orders/CartProduct.php");				//--> Cart
include_once("orders/CartProductAttribute.php");	//--> Cart

require_once('includeHttps.php');

$common 	= new Common();
$objSession	= new Session(DB_TAG_SYSTEM, SESSION_TABLE_NAME);	//-- session

$objCart 	= new Cart();		//--> Cart
$objStrings = new Strings();
$oTimeZone 	= new TimeZone();	//--> TimeZone

$isLogin	= false;

/*----- check session -----*/
if($objSession->exist()) {
	$isLogin	= true;
	
	$customerid = $objSession->getUserID();
}else{
	$location = './login.php';
	
	header("Location: $location");
	exit;
}

session_start();

if($_SESSION['cart'])
	$objCart = unserialize($_SESSION['cart']);


$objOrders		= new Orders(DB_TAG_PUBLIC, $customerid);			//--> Orders

include_once("includeCategory.php");	//--> include category
include_once("includeSpec.php");		//--> include spec


$ordersid = $_GET['ordersid'];

$arrOrders = $objOrders->getRow(DB_TAG_PUBLIC, "SELECT * FROM orders WHERE id = $ordersid");

$arrOrdersProducts	= array();
$arrProducts 		= $objOrders->listCustom(DB_TAG_PUBLIC, '*', "orders_products WHERE ordersID=$ordersid", '', 0, 100, '');
foreach($arrProducts as $key => $row){
	$arrAttribute = $common->getAllData(DB_TAG_PUBLIC, "SELECT * FROM orders_products_attributes WHERE productID = ".$row['productsID']." AND ordersID = $ordersid");
	if(count($arrAttribute) > 0){
		$row['attributes'] 	= $arrAttribute;
	}
	
	$arrOrdersProducts[] = $row;
}

$arrStatusList = array();

$arrAccountList 	= $objOrders->listCustom(DB_TAG_PUBLIC, '*', "orders_account WHERE ordersID=$ordersid", " ORDER BY classes", 0, 100, '');
$arrAllStatusList 	= $objOrders->listCustom(DB_TAG_PUBLIC, '*', "orders_status_history WHERE ordersID=$ordersid", " ORDER BY id", 0, 100, '');
foreach($arrAllStatusList as $row){
	$DatePurchased = $oTimeZone->getTime($row['createdTime'], 'UTC', 'America/Los_Angeles');
	
	$row['datePurchased'] = $DatePurchased;
	
	$arrStatusList[] = $row;
}


/*----- out html -----*/
$smarty = new Smarty();	//-- out template
$smarty->template_dir 	= TEMPLATE_DIR;
$smarty->compile_dir  	= COMPILE_DIR;
$smarty->cache_dir  	= CACHE_DIR;

$smarty->force_compile 	= false;
$smarty->debugging 		= false;
$smarty->caching 		= false;
$smarty->cache_lifetime = 120;

$smarty->assign('error_message', $error_message);

$smarty->assign('HOME_URL', HOME_URL);
$smarty->assign('HOME_URL_HTTP', HOME_URL);

$smarty->assign('categorys', $categorys);
$smarty->assign('topCategory', $topCategory);
$smarty->assign('specProducts', $specProducts);

$smarty->assign('arrOrders', $arrOrders);
$smarty->assign('arrOrdersProducts', $arrOrdersProducts);
$smarty->assign('arrAccountList', $arrAccountList);
$smarty->assign('arrStatusList', $arrStatusList);

$smarty->assign('objCart', $objCart);
$smarty->assign('objStrings', $objStrings);

$smarty->assign('isLogin', $isLogin);

$smarty->display('ordersView.html');
?>
